<?PHP
session_start();
include("../config/connect.php");
include("../public/common.php");

if( !isset($_SESSION["gs_user"]) ) 
{
	$url = "Location:login.php";
	header($url);
}

$showtype = CheckUrlParamNoDie("showtype");
$nPage = SetUrlParamInt("page");
if( $nPage < 0 )
	$nPage = 0;
	
if( $showtype == "a" )
{
	$sql = "select * from return_record where 1 order by id desc";
}
else
{
	$sql = "select * from return_record where trade_id='1' order by id desc";
}
	
$result = mysql_query( $sql );
$row_num = mysql_num_rows( $result );


?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>购物兔</title>
<style type="text/css">
<!--
body,td,th {
	font-family: 宋体;
	font-size: 13px;
	color: #000;
}
body {
	background-color: #FFF;
}
.text_limit{
	width:300px; 
	text-overflow:ellipsis; 
	white-space:nowrap; 
	overflow:hidden;
}

-->
</style>
<script language="javascript">

function ShowAll(  )
{
	window.location.href= "record_list.php?showtype=a";
	//window.location.reload();
}

function ShowDefault(  )
{
	window.location.href= "record_list.php";
	//window.location.reload();
}

function ShowPart(  )
{
	window.location.href= "record_list.php?showtype=p";
	//window.location.reload();
}

function OnPageChange( type )
{
	if( type == "pre" )
	{
		window.location.href= "record_list.php?page=" + "<?PHP echo $nPage - 1; ?>&showtype=<?PHP echo $showtype; ?>";
	}
	else if( type == "next" )
	{
		window.location.href= "record_list.php?page=" + "<?PHP echo $nPage + 1; ?>&showtype=<?PHP echo $showtype; ?>";
	}
	else if( type == "first" )
	{
		window.location.href= "record_list.php?page=0&showtype=<?PHP echo $showtype; ?>";
	}
	else if( type == "last" )
	{
		window.location.href= "record_list.php?&page=<?PHP echo floor($row_num/20); ?>&showtype=<?PHP echo $showtype; ?>";
	}
}

</script>

</head>

<body>
<table cellpadding="0" cellspacing="0" border="1" align="center">
	<tr>
    	<td height="25" width="50" align="center">序列号</td>
        <td width="118" align="center">时间</td>
      	<td width="300" align="center">产品Id</td>
        <td width="68" 	align="center">共返现</td>
        <td width="76" align="center">成交额</td>
        <td width="76" align="center">已返现</td>
        <td width="166" align="center">支付宝帐号</td>
        <td width="100" align="center">订单号</td>
        <td width="87" align="center">手机</td>
        <td width="78" align="center">全部返回</td>
		<td width="50" align="center">对应</td>
    </tr>
<?php

$tb_opt = CheckUrlParamNoDie("tb_opt");
if( $tb_opt == "1" )
{
	$id = SetUrlParamInt( "id" );
	$sql = "update return_record set state=1 where id=$id";
	mysql_query( $sql );
}

$limit = " limit ". $nPage*20 .",20";
if( $showtype == "a" )
{
	$sql = "select * from return_record where 1 order by id desc".$limit;
}
else
{
	$sql = "select * from return_record where trade_id='1' order by id desc".$limit;
}
	
$result = mysql_query( $sql );
while( $result && $row = mysql_fetch_assoc( $result ))
{
?>
<tr title="<?PHP echo $row["info"]; ?>">
    <td height="25" width="50" align="center"><?PHP echo $row["id"]; ?></td>
    <td width="118" align="center" title=""><?PHP echo $row["time"]; ?></td>
	<td width="300" align="center" title="<?PHP echo $row["item_id"]; ?>" class="text_limit"><div class="text_limit"><?PHP echo $row["item_id"]; ?></div>&nbsp;</td>
	<td width="68" 	align="center"><?PHP echo $row["all_return"]; ?>&nbsp;</td>
    <td width="76" align="center"><?PHP echo $row["price"]; ?>&nbsp;</td>
	<td width="76" align="center"><?PHP echo $row["has_return"]; ?>&nbsp;</td>
	<td width="166" align="center"><?PHP echo $row["tb_id"]; ?>&nbsp;</td>
    <td width="100" align="center"><?PHP echo $row["trade_id"]; ?>&nbsp;</td>
    <td width="87" align="center"><?PHP echo $row["phone"]; ?>&nbsp;</td>
	<td width="78" align="center"><?PHP echo $row["b_return"] == 1?"是":"否"; ?></td>
	<td width="78" align="center"><?PHP if( $row["state"] == 1 )
											echo "<strong><span style=\"color:#F00\">是</span></strong>";
										else 
											echo "<a href=\"record_list.php?id=".$row["id"]."&tb_opt=1&page=$nPage\">否</a>"; ?></td>
</tr>
<?PHP
}
?>
</table>
<table cellpadding="0" cellspacing="0" border="0" align="center">
	<tr>
    	<td width="800" height="30" align="center">&nbsp;&nbsp;<input type="button" value="显示所有" onclick="javascript:ShowAll()" />&nbsp;&nbsp;
        <input type="button" value="显示部分" onclick="javascript:ShowPart()" />&nbsp;&nbsp;&nbsp;<a href="#" onclick="javascript:OnPageChange('first');">首页</a>&nbsp;&nbsp;<a href="#" onclick="javascript:OnPageChange('next');">下页</a>&nbsp;&nbsp;<a href="#" onclick="javascript:OnPageChange('pre');">上页</a>&nbsp;&nbsp;<a href="#" onclick="javascript:OnPageChange('last');">末页</a></td>
    </tr>
</table>
</body>
</html>
